﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using System.Data;

namespace WebPresentation
{
    public partial class Position : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButtonadd_Click(object sender, ImageClickEventArgs e)
        {
            PositionBO PosBo = new PositionBO();
            string name = txtposition.Text;
            string code = txtpositioncode.Text;
            if (PosBo.AddNewPosition(name, code) > 0)
            {
                Label10.Text = "Add successfully";
                dtgposition.DataBind();
            }
            else
            {
                Label10.Text = "Add failed!";
            }
        }

        protected void dtgposition_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt = new PositionBO().GetByID(Convert.ToInt32(dtgposition.SelectedRow.Cells[1].Text));
            txtposition.Text = dt.Rows[0]["pName"].ToString();
            txtpositioncode.Text = dt.Rows[0]["pCode"].ToString();
            Label11.Text = dt.Rows[0]["pID"].ToString();
        }

        protected void ImageButtonEdit_Click(object sender, ImageClickEventArgs e)
        {
            PositionBO PosBo = new PositionBO();
            string name = txtposition.Text;
            string code = txtpositioncode.Text;
            int id = Int32.Parse(Label11.Text);
            if (PosBo.UpdatePosition(name, code, id) > 0)
            {
                Label10.Text = "Update successfully";
                dtgposition.DataBind();
            }
            else
            {
                Label10.Text = "Update failed!";
            }
        }

        protected void ImageButtonDel_Click(object sender, ImageClickEventArgs e)
        {
            PositionBO PosBo = new PositionBO();
            int id = Int32.Parse(Label11.Text);
            if (PosBo.DeletePosition(id) > 0)
            {
                Label10.Text = "Delete successfully";
                dtgposition.DataBind();
            }
            else
            {
                Label10.Text = "Delete failed";
            }
        }
    }
}